﻿using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using TTGameEngine;
using System.Reflection;
using TTGame;
using System;

/*
 * OptionIDPropertyDrawer
 *
 * 让OptionID在Inspector中拥有和LayerMask一样的可选Popup控件。
 *
 *
 *
 * 依赖：
 *
 * ！不写重复代码！
 * @author TTun
 * @date 7/28/2017 9:04:44 AM
 */
public class OptionIDPropertyDrawer : PropertyDrawer {
    bool init = false;
    IOptionID optionObj = null;

    public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label) {
        if(init == false) {
            optionObj = _property.GetSerializePropertyFieldObj() as IOptionID;
            init = true;
        }

        if(optionObj != null) {
            EditorGUI.BeginProperty(_position, GUIContent.none, _property);

            optionObj.Set(EditorGUI.MaskField(_position, _label, optionObj.LayerIndex, optionObj.Names));

            EditorGUI.EndProperty();
        }
    }

}


[CustomPropertyDrawer(typeof(TargetTypeID))]
public class TargetTypeIDPropertyDrawer : OptionIDPropertyDrawer {
    public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label) {
        base.OnGUI(_position, _property, _label);
    }
}
